package module.service.impl;

import common.bean.SearchPageResult;
import common.bean.SearchParameter;
import module.dao.AssessmentDataDao;
import module.model.AssessmentDataModel;
import module.service.AssessmentDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 资料
 */
@Service
public class AssessmentDataServiceImpl implements AssessmentDataService {
    @Autowired
    private AssessmentDataDao assessmentDataDao;
    @Transactional
    public List<AssessmentDataModel> getAssessmentDataModelListBySearchParameter(SearchParameter searchParameter) {
        return assessmentDataDao.getAssessmentDataModelListBySearchParameter(searchParameter);
    }

    @Transactional
    public List<AssessmentDataModel> getAssessmentDataModelListByFormId(Long formId) {
        SearchParameter searchParameter = new SearchParameter();
        searchParameter.addParam("formId",formId);
        return getAssessmentDataModelListBySearchParameter(searchParameter);
    }

    @Transactional
    public AssessmentDataModel saveAssessmentDataModel(AssessmentDataModel assessmentDataModel) {
        if(assessmentDataModel.getDataId()==null){
            assessmentDataModel.setCreateDate(new Date());
            assessmentDataDao.save(assessmentDataModel);
        }else{
            assessmentDataDao.update(assessmentDataModel);
        }
        return assessmentDataModel;
    }

    @Transactional
    public void deleteAssessmentDataModelById(Long dataId) {
        assessmentDataDao.deleteById(AssessmentDataModel.class,dataId);
    }

    @Transactional
    public SearchPageResult<AssessmentDataModel> getAssessmentDataModelListPage(SearchParameter searchParameter) {
        return assessmentDataDao.getAssessmentDataModelListPage(searchParameter);
    }

    @Transactional
    public AssessmentDataModel getAssessmentDataModelByDataId(Long dataId) {
        return assessmentDataDao.load(AssessmentDataModel.class,dataId);
    }
}
